package com.cloudwise.service.impl;

import com.cloudwise.dao.DeptDao;
import com.cloudwise.entity.Dept;
import com.cloudwise.entity.DeptVo;
import com.cloudwise.service.DeptService;
import com.cloudwise.util.MySqlSessionFactory;
import lombok.extern.java.Log;
import org.apache.ibatis.session.SqlSession;

import java.util.List;


/**
 * (Dept)表服务实现类
 *
 * @author
 * @since 2021-09-30 10:01:37
 */
//@Service("deptService")
    @Log
public class DeptServiceImpl implements DeptService {
    //@Resource
    private SqlSession sqlSession=MySqlSessionFactory.getSqlSession();
    private DeptDao deptDao= sqlSession.getMapper(DeptDao.class);

    /**
     * 通过ID查询单条数据
     *
     * @param deptno 主键
     * @return 实例对象
     */
    @Override
    public Dept queryById(Integer deptno) {
        return this.deptDao.queryById(deptno);
    }

    @Override
    public List<Dept> queryAll() {
        return deptDao.queryAll();
    }

    @Override
    public List<DeptVo> queryAllAvg() {
        return deptDao.queryAllAvg();
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */

  /*  @Override
    public Page<Dept> queryByPage(Dept dept, PageRequest pageRequest) {
        long total = this.deptDao.count(dept);
        return new PageImpl<>(this.deptDao.queryAllByLimit(dept, pageRequest), pageRequest, total);
    }*/

    /**
     * 新增数据
     *
     * @param dept 实例对象
     * @return 实例对象
     */
    @Override
    public Dept insert(Dept dept) {
        log.info("插入dept对象"+dept.toString());
        this.deptDao.insert(dept);
        sqlSession.commit();
        return dept;
    }

    @Override
    public Dept update(Dept dept) {
        return null;
    }

    /**
     * 修改数据
     *
     * @param dept 实例对象
     * @return 实例对象
     */
   /* @Override
    public Dept update(Dept dept) {
        this.deptDao.update(dept);
        sqlSession.commit();
        return this.queryById(dept.getDeptno());
    }*/

    /**
     * 通过主键删除数据
     *
     * @param deptno 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer deptno) {
        int i = this.deptDao.deleteById(deptno);
        sqlSession.commit();
        return i > 0;
    }
}
